﻿<!--
 * @Author: your name
 * @Date: 2021-04-07 16:52:04
 * @LastEditTime: 2021-04-08 10:47:14
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \project-src-svnc:\Users\glr\Desktop\flvjs(1)(1)\flvjs\index.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="flv.js" type="text/javascript"></script>
</head>

<body>
    <input type="text" name="videoUrl" id="videoUrl" style="width:400px; height:20px;"/>
    <button onclick="play()">播放视频</button>
    <button onclick="closeVideo()">关闭视频</button>
    <br />
    <video width="720" height="360" id="videoElement"></video>

    <script>
        var flvPlayer;
        function play() {
            if (flvjs.isSupported()) {
                if (flvPlayer) {
                    flvPlayer.pause();
                    flvPlayer.unload();
                    flvPlayer.detachMediaElement();
                    flvPlayer.destroy();
                    flvPlayer = null;
                }

                var videoElement = document.getElementById('videoElement');
                var videoUrl = document.getElementById('videoUrl').value;
                console.log(videoUrl);
                flvPlayer = flvjs.createPlayer({
                    type: 'flv',
                    isLive: true,
                    cors:true,
                    withCredentials:false,
                    enableStashBuffer:true,
                    hasAudio: false,
                    //url: 'ws://10.187.19.221:9002/21757'
                    url: videoUrl
                }, {
                    enableWorker: true,
                    autoCleanupSourceBuffer: true,
                    autoCleanupMaxBackwardDuration: 5,
                    autoCleanupMinBackwardDuration: 2,
                    enableStashBuffer: false,
                    fixAudioTimestampGap: false,
                    stashInitialSize: 0
                });
                flvPlayer.attachMediaElement(videoElement);
                flvPlayer.load();
                flvPlayer.play();
            }
        }
        function closeVideo() {
            if (flvPlayer) {
                flvPlayer.pause();
                flvPlayer.unload();
                flvPlayer.detachMediaElement();
                flvPlayer.destroy();
                flvPlayer = null;
            }
        }
    </script>
</body>

</html>